#!/usr/bin/env sh




install() {
    read -p "input PECL-NAME:"  pecl
    pecl_name=`echo -e $pecl|awk -F "-" '{print $1}'`
    apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS
    cd /usr/src
    wget -O pecl.tgz "http://pecl.php.net/get/$pecl.tgz"
    echo "http://pecl.php.net/get/$pecl.tgz"
    mkdir /usr/src/pecl
    tar zxvf pecl.tgz -C pecl --strip-components 1
    cd /usr/src/pecl
    phpize
    ./configure
    make
    make install
    echo "extension=$pecl_name.so">"/usr/local/etc/php/conf.d/$pecl_name.ini"
    apk del .build-deps
    rm -rf /usr/src/pecl*
}


uninstall() {
    read -p "input PECL-NAME:"  pecl
    pecl_name=`echo -e $pecl|awk -F "-" '{print $1}'`
    rm -rf "/usr/local/lib/php/extensions/no-debug-zts-20100525/$pecl_name.so"
    rm -rf "/usr/local/etc/php/conf.d/$pecl_name.ini"
    echo "del $pecl_name Success.."
}


usage() {
	echo "usage: $0 COMMAND"
	echo
	echo "Manage php PECL."
	echo
	echo "Commands:"
	echo "   add  install PECL to the computer.."
	echo "   del   uninstall PECL to the computer.."
	echo
}

case "$1" in
	add)
		install
		;;
	del)
		uninstall
		;;
	*)
		usage
		exit 1
		;;
esac


